#include "Precompiled.h"
#include "GameEngine.h"

#include "../Common/SceneManager.h"
#include "../Common/EntityLogicManager.h"
#include "../Logic/SceneManagerLogic.h"
#include "../Logic/EntityLogicInitializer.h"

namespace Game {
namespace GameEngine {

GameEngine::GameEngine() :
        entityLogicManager(new EntityLogicManager()),
        sceneManager(new SceneManager()) {
    this->sceneManager->SetEntityLogicManager(this->entityLogicManager);
}

GameEngine::~GameEngine() {
    SAFE_DELETE(this->entityLogicManager);
    SAFE_DELETE(this->sceneManager);
}

EntityLogicManager* GameEngine::GetGameLogicManager() const {
    return this->entityLogicManager;
}

SceneManager* GameEngine::GetSceneManager() const {
    return this->sceneManager;
}

void GameEngine::Finalize() {
    EntityLogicInitializer::Finalize(*this->entityLogicManager);
}

void GameEngine::Initialize() {
    EntityLogicInitializer::Initialize(*this->entityLogicManager);
    IEntityLogic* gameLogic = this->entityLogicManager->GetEntityLogic(SceneManager::rtti);
    this->sceneManagerLogic = safe_pointer_cast<SceneManagerLogic>(gameLogic);
}

void GameEngine::Update(const double& fTime, const float& fElapsedTime) {
    this->sceneManagerLogic->Update(this->sceneManager, fElapsedTime);
}

}
}